/*
 * OREKIT-X
 * Copyright 2002-2008 CS Communication & Systemes
 * 
 * Parts of this software package have been licensed to CS
 * Communication & Systemes (CS) under one or more contributor license
 * agreements.  See the NOTICE file distributed with this work for
 * additional information.
 *  
 * This is an experimental copy of OREKIT from www.orekit.org.
 * Please use the original OREKIT from orekit.org for normal work
 * unrelated to this research project.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you
 * may not use this file except in compliance with the License.  You
 * may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied.  See the License for the specific language governing
 * permissions and limitations under the License.
 */
package ore.frames;

import ore.Transform;

import org.apache.commons.math.geometry.Rotation;
import org.apache.commons.math.geometry.Vector3D;

/** 
 * EME2000 frame : mean equator at J2000.0.
 * 
 * This frame was the standard inertial reference prior to GCRF. It was defined
 * using Lieske precession-nutation model for Earth. This frame has been superseded
 * by GCRF which is implicitly defined from a few hundred quasars coordinates.
 * 
 * The transformation between GCRF and EME2000 is a constant rotation bias.
 * 
 * @author Luc Maisonobe
 */
public class EME2000Frame
    extends ore.Frame
{
    protected static EME2000Frame Instance;
    public static EME2000Frame Instance(){
        if (null == Instance)
            Instance = new EME2000Frame();
        return Instance;
    }

    /** 
     * Obliquity of the ecliptic.
     */
    private static final double EPSILON_0 = 84381.44 * RADIANS_PER_ARC_SECOND;
    /** 
     * Bias in longitude.
     */
    private static final double D_PSI_B = -0.041775 * RADIANS_PER_ARC_SECOND;
    /** 
     * Bias in obliquity.
     */
    private static final double D_EPSILON_B = -0.0068192 * RADIANS_PER_ARC_SECOND;
    /**
     * Right Ascension of the 2000 equinox in ICRS frame.
     */
    private static final double ALPHA_0 = -0.0146 * RADIANS_PER_ARC_SECOND;


    private EME2000Frame(){
        this("EME2000");
    }
    protected EME2000Frame(String name) {
        super(ore.Frame.getRoot(), null, name);
        /*
         * Build the bias transform
         */
        final Rotation r1 = new Rotation(Vector3D.PLUS_I, D_EPSILON_B);
        final Rotation r2 = new Rotation(Vector3D.PLUS_J, -D_PSI_B * Math.sin(EPSILON_0));
        final Rotation r3 = new Rotation(Vector3D.PLUS_K, -ALPHA_0);
        final Rotation bias = r1.applyTo(r2.applyTo(r3));
        /*
         * Store the bias transform
         */
        this.setTransform(new Transform(bias));

        Instance = this;
    }

}
